﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace FaWorks.WebSite.Controllers
{
    public class CodeController : Controller
    {
        //
        // GET: /Code/

        public ActionResult RenderView(string type, string view)
        {
            string path;
            switch (type.ToUpper()) {
                case "View":
                    path = Server.MapPath(String.Format("~/Views/{0}.cshtml", view.Replace("-", "/")));
                    break;
                case "Controller":
                    path = Server.MapPath(String.Format("~/Controllers/{0}Controller.cs", view.Replace("-", "/")));
                    break;
                default:
                    path = Server.MapPath(String.Format("~/Content/{0}.{1}", view.Replace("-", "/"), type));
                    break;
            }
            var content = System.IO.File.ReadAllText(path, System.Text.Encoding.UTF8);

            return Content(content, "text/plain");
        }

    }
}
